package com.tiger.admin.http.statistics;

import com.tiger.db.entity.AppCategory;
import com.tiger.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    private final StatisticsService statisticsService;

    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    @GetMapping("category")
    public Object category() {
        List<AppCategory> categoryList = statisticsService.topCategory();
        return ResponseUtil.successRes(categoryList);
    }

    //查询app分类下的app总数
    @GetMapping("appCount/{category}")
    public Object appCount(@PathVariable("category") Integer category) {
        return ResponseUtil.successRes(statisticsService.appCountOfCategory(category));
    }

    //分类的访客人数
    @GetMapping("uniqueVisitors/{category}")
    public Object uniqueVisitors(@PathVariable("category") Integer category) {
        return ResponseUtil.successRes(statisticsService.uniqueVisitors(category));
    }

    //访问次数
    @GetMapping("visitTimes/{category}")
    public Object visitTimes(@PathVariable("category") Integer category) {
        return ResponseUtil.successRes(statisticsService.visitTimes(category));
    }

    //服务类型分布
    @GetMapping("category/appCount")
    public Object categoryAppCount() {
        return ResponseUtil.successRes(statisticsService.categoryAppCount());
    }

    //访问次数按月排序
    @GetMapping("rankVisitTimesByMonth")
    public Object rankVisitTimesByMonth(@RequestParam("month") String month) {
        return ResponseUtil.successRes(statisticsService.rankVisitTimesByMonth(month, 5));
    }

    //访问次数按年排序
    @GetMapping("rankVisitTimesByYear")
    public Object rankVisitTimesByYear(@RequestParam("year") String year) {
        return ResponseUtil.successRes(statisticsService.rankVisitTimesByYear(year, 5));
    }
}
